/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CONTROLLER;

import BUS.ChitietdonhangBUS;
import BUS.DonhangBUS;
import BUS.TinhtrangdonhangBUS;
import POJO.Donhang;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author nhlvu07db373
 */
@Controller
public class HoadonController {

    private DonhangBUS dhBUS;
    private ChitietdonhangBUS ctdhBUS;
    private TinhtrangdonhangBUS ttdhBUS;

    @RequestMapping(value = "/quanlidathang")
    public ModelAndView dathangshow(HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.setContentType("text/html;charset=UTF-8");
        Map<String, Object> mv = new HashMap<String, Object>();
        //Do something...
        try {
            List dsDH = dhBUS.dsDonhangFi(1);
            List dslct = new ArrayList();
            for (int i = 0; i < dsDH.size(); i++) {
                Donhang dh = (Donhang) dsDH.get(i);
                List dsct = ctdhBUS.dsChitietdonhang(dh.getMaDonHang(), 1);
                dslct.add(dsct);
            }
            mv.put("lstDH", dsDH);
            mv.put("lstlct", dslct);

        } catch (Exception ex) {
            System.err.print(ex);
        }
        return new ModelAndView("quanlidathangview", mv);
    }

    @RequestMapping(value = "/adminhuydathang")
    public ModelAndView chitietdonhangshow(HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.setContentType("text/html;charset=UTF-8");
        Map<String, Object> mv = new HashMap<String, Object>();
        //Do something...
        try {
            String maHD = request.getParameter("MaHD");
            dhBUS.adminhuyDonHang(maHD);
            List dsDH = dhBUS.dsDonhangFi(1);
            List dslct = new ArrayList();
            for (int i = 0; i < dsDH.size(); i++) {
                Donhang dh = (Donhang) dsDH.get(i);
                List dsct = ctdhBUS.dsChitietdonhang(dh.getMaDonHang(), 1);
                dslct.add(dsct);
            }
            mv.put("lstDH", dsDH);
            mv.put("lstlct", dslct);
        } catch (Exception ex) {
            System.err.print(ex);
        }
        return new ModelAndView("quanlidathangview", mv);
    }

    @RequestMapping(value = "/adminchapnhandathang")
    public ModelAndView chapnhandonhang(HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.setContentType("text/html;charset=UTF-8");
        Map<String, Object> mv = new HashMap<String, Object>();
        //Do something...
        try {
            String maHD = request.getParameter("MaHD");
            dhBUS.adminchapnhanDonHang(maHD);
            List dsDH = dhBUS.dsDonhangFi(1);
            List dslct = new ArrayList();
            for (int i = 0; i < dsDH.size(); i++) {
                Donhang dh = (Donhang) dsDH.get(i);
                List dsct = ctdhBUS.dsChitietdonhang(dh.getMaDonHang(), 1);
                dslct.add(dsct);
            }
            mv.put("lstDH", dsDH);
            mv.put("lstlct", dslct);
        } catch (Exception ex) {
            System.err.print(ex);
        }
        return new ModelAndView("quanlidathangview", mv);
    }

    @Autowired
    public void setDhBUS(DonhangBUS dhBUS) {
        this.dhBUS = dhBUS;
    }

    @Autowired
    public void setCtdhBUS(ChitietdonhangBUS ctdhBUS) {
        this.ctdhBUS = ctdhBUS;
    }

    @Autowired
    public void setTtdhBUS(TinhtrangdonhangBUS ttdhBUS) {
        this.ttdhBUS = ttdhBUS;
    }
}
